import constants as con
import pygame
import math

class Label(pygame.sprite.Sprite):
    imFood = None
    imDrink = None
    imHealth = None
    imLuxury = None
    imShelter = None
    imTrash = None
    imBall = None
    imCouch = None
    imCar = None
    imPhone = None
    imGame = None

    def __init__(self,parent):
        pygame.sprite.Sprite.__init__(self)

        if Label.imFood is None:
            Label.imFood = con.load_image('lab_food.png')
        if Label.imDrink is None:
            Label.imDrink = con.load_image('lab_drink.png')
        if Label.imHealth is None:
            Label.imHealth = con.load_image('lab_health.png')
        if Label.imLuxury is None:
            Label.imLuxury = con.load_image('lab_luxury.png')
        if Label.imShelter is None:
            Label.imShelter = con.load_image('lab_shelter.png')
        if Label.imTrash is None:
            Label.imTrash = con.load_image('lab_trash.png')
        if Label.imBall is None:
            Label.imBall = con.load_image('lab_ball.png')
        if Label.imCouch is None:
            Label.imCouch = con.load_image('lab_couch.png')
        if Label.imCar is None:
            Label.imCar = con.load_image('lab_car.png')
        if Label.imPhone is None:
            Label.imPhone = con.load_image('lab_phone.png')
        if Label.imGame is None:
            Label.imGame = con.load_image('lab_game.png')

        #self.width = int(con.window_size[0] * 0.03125)
        #self.height = int(con.window_size[1] * 0.0417)
        self.width = parent.width
        self.height = parent.height

        if parent.need == 'health':
            self.image = self.master = pygame.transform.scale(Label.imHealth, (self.width,self.height))
        elif parent.need == 'food':
            self.image = self.master = pygame.transform.scale(Label.imFood, (self.width,self.height))
        elif parent.need == 'luxury':
            self.image = self.master = pygame.transform.scale(Label.imLuxury, (self.width,self.height))
        elif parent.need == 'shelter':
            self.image = self.master = pygame.transform.scale(Label.imShelter, (self.width,self.height))
        elif parent.need == 'drink':
            self.image = self.master = pygame.transform.scale(Label.imDrink, (self.width,self.height))
        elif parent.need == 'trash':
            self.image = self.master = pygame.transform.scale(Label.imTrash, (self.width,self.height))
        elif parent.need == 'ball':
            self.image = self.master = pygame.transform.scale(Label.imBall, (self.width,self.height))
        elif parent.need == 'couch':
            self.image = self.master = pygame.transform.scale(Label.imCouch, (self.width,self.height))
        elif parent.need == 'car':
            self.image = self.master = pygame.transform.scale(Label.imCar, (self.width,self.height))
        elif parent.need == 'phone':
            self.image = self.master = pygame.transform.scale(Label.imPhone, (self.width,self.height))
        elif parent.need == 'game':
            self.image = self.master = pygame.transform.scale(Label.imGame, (self.width,self.height))

        self.parent = parent
        self.sprites = parent.sprites

        w = self.image.get_width()
        h = self.image.get_height()

        x,y = self.parent.rect.topleft

        self.rect = pygame.Rect(x,y,w,h)
        self.sprites.add(self)
    
    def update(self):
        if not self.parent.body is None:
            self.image = pygame.transform.rotate(self.master, math.degrees(self.parent.body.angle))
        self.rect = self.parent.rect

    def purge(self):
        self.sprites.remove(self)
